package com.googlecode.gxtmvp.rest.client;

import java.util.HashMap;
import java.util.Map;

public class RestCommand<D, C> {
  private final String method;
  private final String uri;
  private final Map<String, String> params;
  private final Codec<String, C, D> codec;
  private final C config;
  private D data;
  
  protected RestCommand(final String method, final String uri) {
    this(method, uri, null, null, null, new HashMap<String, String>());
  }
  
  protected RestCommand(final String method, final String uri, final Codec<String, C, D> codec, final C config) {
    this(method, uri, null, codec, config, new HashMap<String, String>());
  }
  
  protected RestCommand(final String method, final String uri, final D data, final Codec<String, C, D> codec,
      final C config) {
    this(method, uri, data, codec, config, new HashMap<String, String>());
  }
  
  protected RestCommand(final String method, final String uri, final D data, final Codec<String, C, D> codec,
      final C config, final Map<String, String> params) {
    this.method = method;
    this.uri = uri;
    this.params = params;
    this.codec = codec;
    this.config = config;
    this.data = data;
  }
  
  public Codec<String, C, D> getCodec() {
    return codec;
  }
  
  public C getConfig() {
    return config;
  }
  
  public D getData() {
    return data;
  }
  
  public String getMethod() {
    return method;
  }
  
  public Map<String, String> getParams() {
    return params;
  }
  
  public String getUri() {
    return uri;
  }
  
  public void setData(final D data) {
    this.data = data;
  }
  
  public RestCommand<D, C> withParams(final Map<String, String> params) {
    return new RestCommand<D, C>(method, uri, data, codec, config, params);
  }
}
